package com.phei.netty.codec.marshalling;

import com.phei.netty.codec.pojo.Request;
import com.phei.netty.codec.pojo.Response;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;


@Sharable
public class ServerHandler extends ChannelHandlerAdapter {


    public void channelRead(ChannelHandlerContext ctx, Object msg)
            throws Exception {
        Request req = (Request) msg;
        System.out.println(req);
        ctx.writeAndFlush(new Response());
    }


    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();// 发生异常，关闭链路
    }
}
